Customizable partner form#287
Conversation
edwinthinks
left a comment
There was a problem hiding this comment.
Looks pretty good! I left some comments :)
| end | ||
|
|
||
| def valid_partner_form_creation_request( | ||
| diaper_bank_id: 123, |
There was a problem hiding this comment.
| diaper_bank_id: 123, | |
| diaper_bank_id: Faker::Number.number, |
|
|
||
| describe "#partials_to_show" do | ||
| let(:partner) { create(:partner, diaper_bank_id: 100) } | ||
| it 'has 9 partials when there are no displayable partials configured' do |
There was a problem hiding this comment.
| it 'has 9 partials when there are no displayable partials configured' do | |
| it 'has 9 partials when there are no displayable partials configured' do |
|
|
||
| it 'displays the number of displayable partials when they are configured' do | ||
| partner.diaper_bank_id = 100 | ||
| FactoryBot.create(:partner_form, diaper_bank_id: 100, |
There was a problem hiding this comment.
| FactoryBot.create(:partner_form, diaper_bank_id: 100, | |
| FactoryBot.create(:partner_form, diaper_bank_id: partner.id, |
Since partner is already defined above with let could we just use the partner from there?
| describe "#partials_to_show" do | ||
| let(:partner) { create(:partner, diaper_bank_id: 100) } | ||
| it 'has 9 partials when there are no displayable partials configured' do | ||
| expect(partner.partials_to_show.size).to eq(9) |
There was a problem hiding this comment.
| expect(partner.partials_to_show.size).to eq(9) | |
| expect(partner.partials_to_show).to eq(Partner::ALL_PARTIALS) |
^ this might make the test a bit more robust, so when you add a new field you won't have to worry about fixing this spec.
| end | ||
|
|
||
| def displayable_partials | ||
| PartnerForm.find_by(diaper_bank_id: diaper_bank_id)&.sections |
There was a problem hiding this comment.
| PartnerForm.find_by(diaper_bank_id: diaper_bank_id)&.sections | |
| PartnerForm.find_by(diaper_bank_id: diaper_bank_id)&.sections |
Can we can add the has_one association to get this instead of putting a query here?
has_one :partner_form, primary_key: :diaper_bank_id, foreign_key: :diaper_bank_id
^ This should work and allow you to use partner_form in place of the Partner.find_by(...)
| displayable_partials || ALL_PARTIALS | ||
| end | ||
|
|
||
| def displayable_partials |
There was a problem hiding this comment.
Could we put this as a private method since it is only being used in the partial_to_show right now?
|
|
||
| RSpec.describe PartnerForm, type: :model do | ||
| subject do | ||
| described_class.new(diaper_bank_id: 1) |
There was a problem hiding this comment.
| described_class.new(diaper_bank_id: 1) | |
| described_class.new(diaper_bank_id: Faker::Number.number) |
0d9ed76 to
c48e318
Compare
c48e318 to
dcdad79
Compare
|
Addressed your comments. Most of them anyway. |

This is part of the customizations to allow diaper banks to select which sections of the partner form they want them to be able to edit.